Python RegEx Split – re.split()

172

from re import split

# '\W+' denotes Non-Alphanumeric Characters or group of characters Upon finding ',' or whitespace ' ', the split(), splits the string from that point
print(split('\W+', 'Words, words , Words'))
print(split('\W+', "Word's words Words"))

# Here ':', ' ' ,',' are not AlphaNumeric thus, the point where splitting occurs
print(split('\W+', 'On 5th Jan 1999, at 11:02 AM'))

# '\d+' denotes Numeric Characters or group of characters Splitting occurs at '5', '1999','11', '02' only
print(split('\d+', 'On 5th Jan 1999, at 11:02 AM'))

Comments

Submit
0 Comments